{include file="admin@public/header"/}

<link rel="stylesheet" href="/public/static/admin/css/report.css" />
<link rel="stylesheet" href="/public/static/admin/easyui/layui-v2.6.8/css/layui.css">
<!-- <link rel="stylesheet" type="text/css" href="/public/static/admin/easyui/jeasyui/themes/icon.css"> -->
<style>
	.ui-icon-ellipsis {
		right: 5px;
	}

	#filter-menu .con {
		width: 355px;
	}

	#filter-menu label.tit {
		width: 80px;
	}

	/*.ui-jqgrid tr.jqgrow td {
	white-space: normal !important;
	}
	*/
	.no-query {
		background: url("/public/static/admin/css/img/no_query.png") no-repeat scroll 100px 60px #fff;
		background-position: center;
		border: 1px solid #ddd;
		border-top: none;
		height: 402px;
		margin-right: 0;
	}

	.box-flex {
		overflow: hidden;
		zoom: 1;
	}

	.box-flex .flex {
		float: left;
		width: 33.3%;
	}

	.grid-title {
		font-size: 24px;
		text-align: center;
		clear: none;
	}

	.ui-print .grid-wrap {
		padding: 10px 0 0 30px;
	}

	#conditions-trigger {
		background: url(/public/static/admin/css/img/bg.png) no-repeat;
		border: 0px;
		width: 74px;
		box-shadow: 0px 0px;
	}

	#filter-menu .conditions-trigger>b {
		position: absolute;
		right: 0;
		top: 50%;
		margin-top: -8px;
		width: 16px;
		height: 16px;
		background: url(/public/static/admin/css/img/down.png) 2px 5px no-repeat;
	}

	#filter-menu .conditions-trigger>b.act {
		background: url(/public/static/admin/css/img/up.png) 2px 5px no-repeat;
	}

	#filter-menu .btns {
		position: absolute;
		top: 7px;
		right: 0px;
	}

	.layui-form-checkbox[lay-skin=primary] i {
		padding: 0;
	}

	.layui-form-checked[lay-skin=primary] i {
		border-color: #5dc5e7;
		background-color: #5dc5e7;
		color: #fff;
		padding: 0;
	}

	.layui-form-checkbox[lay-skin=primary]:hover i {
		border-color: #5dc5e7;
	}

	

	@media print {
    /* 页边距 */
		@page {margin:.5cm;}
		* {background:transparent !important; color:#333 !important; box-shadow:none !important; text-shadow:none !important; filter:0 !important; -ms-filter:0 !important;}
		thead {display: table-row-group !important;}/*table-header-group导致页面中出现表头与内容重叠的现象，表头只需在第一页显示即可*/
		tr,td,img {page-break-inside:avoid;}
		h2,h3 {page-break-after:avoid;}
		p,h2,h3 {orphans:3; widows:3;}
		table{width:100% !important;padding:0 !important;margin:0;}
		table th{width:0px !important;padding:0 5px !important;font-size: 12px !important;min-width: 0 !important;}
		table td{width:0px !important;white-space: normal !important;word-break:break-all !important;padding:0 5px !important;font-size: 12px !important;min-width: 0 !important;}
		/* 打印不要出现滚动条 */
		.ui-jqgrid .ui-jqgrid-bdiv,
		.ui-jqgrid .ui-jqgrid-bdiv>div{
			height: auto !important;
			width: 100% !important;
			font-size: 12px !important;
		}
	}
</style>

<div class="wrapper">
	<!-- header -->
	<div class="mod-search cf">
		<form class="layui-form">
			<div class="l  " id="filter-menu">
				<ul class="ul-inline fix" id="filterItems" style="height: 44px;">
					<li id="date" style="display: list-item;"><label>单据日期:</label>
						<input type="date" id="startdate" class="ui-input " value="" style="width: 125px;">
						<span class="todate"> 至 </span>
						<input type="date" id="enddate" class="ui-input " value="" style="width: 125px;">
					</li>

					<!-- 选择供应商 -->
					{include file="admin@select/supplier"/}

					<!-- 选择商品 -->
					{include file="admin@select/goods"/}

					<li id="billNum" style="display: list-item;">
						<label>订单号</label>
						<input type="text" value="" style="width:115px;font-size: 12px;" class="ui-input ui-input-ph"
							name="sn" id="sn" placeholder="请输入单号查询">
					</li>

					<!-- 选择供应商类别 -->
					{include file="admin@select/supplier_category"/}

					<li id="deliveryDate" style="display: list-item;">
						<label>预计交货日:</label>
						<input type="date" id="jh_time_start" class="ui-input " value="" style="width: 125px;">
						<span class="todate"> 至 </span>
						<input type="date" id="jh_time_end" class="ui-input " value="" style="width: 125px;">
					</li>
					<li id="status-wrap" style="display: list-item;padding-top: 11px;">
						<label>状态:</label>
						<input type="checkbox" name="status" id="" lay-skin="primary" title="未入库" value="1" checked="">
						<input type="checkbox" name="status" id="" lay-skin="primary" title="部分入库" value="2" checked="">
						<input type="checkbox" name="status" id="" lay-skin="primary" title="已入库" value="3" checked="">
					</li>
					<li id="status-order-wrap"
						style="display: list-item;padding-top: 14px;height: 44px;box-sizing: border-box;">
						<input type="checkbox" name="status" id="" lay-skin="primary" title="已关闭" value="4">
					</li>
					<li class="chk-list" id="chk-wrap"
						style="display: list-item;padding-top: 14px;height: 44px;box-sizing: border-box;">
						<input type="checkbox" name="status" id="chk-wrap-good" lay-skin="primary" title="按商品排列" value="5" checked="" lay-filter="chk-wrap-filter">
						<input type="checkbox" name="status" id="chk-wrap-date" lay-skin="primary" title="按单据排列" value="6" lay-filter="chk-wrap-filter">
					</li>
					<li id="showSubtotal" style="display: list-item;padding-top: 14px;height: 44px;box-sizing: border-box;">
						<input type="checkbox" name="status" id="showSubtotalStatus" lay-skin="primary" title="显示小计" value="7" checked="">
					</li>
					<li id="includeStatus"
						style="display: list-item;padding-top: 14px;height: 44px;box-sizing: border-box;">
						<input type="checkbox" name="status" id="" lay-skin="primary" title="包含未审核订单" value="8" checked="">
					</li>


					<div class="btns" style="top:0;"><a class="ui-btn mrb ui-btn-search" id="search">查询</a></div>
					<!-- <span class="url-box" id="openUrl"><a href="https://club.kingdee.com/club/newclub/school/course?product_id=7&amp;cid=1548#pid=5713" target="_blank" class="video-icon" style="margin-right: 5px;"></a>功能简介</span> -->
				</ul>
				<a href="#" id="conditions-trigger" class="ui-btn conditions-trigger" tabindex="-1">&nbsp;更多条件<b></b></a>
			</div>
		</form>
	</div>

	<!-- 下拉树选择（供应商类别） -->
	{include file="admin@popup/supplier_category"/}

	<!-- no data -->
	<div class="no-query"></div>
	<!-- grid begin -->
	<div class="ui-print" id="ui-print" style="visibility: hidden;">
		<!-- 列配置 -->
		<div class="cf box-flex">
			<div class="flex">
				<span id="config" class="ui-config"><a href="#" class="ui-icon-config-new"></a>列设置</span>
			</div>

			<div class="grid-title flex">采购订单跟踪表</div>
			<div class="fr">
				<a href="#" class="ui-btn ui-btn-export btn-sm mrb fl" id="export">导出</a>
				<a href="javascript:void(0)" class="ui-btn ui-btn-print btn-sm fl" id="btn-print" onclick="preview(1)">打印</a>

				<!-- <a href="javascript:void(0)" class="ui-btn ui-btn-print btn-sm fl" id="btn-printAAA">测试打印</a> -->
			</div>
		</div>

		<div class="grid-wrap" id="grid-wrap" style="padding-bottom: 30px;padding-right: 30px;">
			<!--startprint1-->
			<div class="grid-title" id="gridTitle" style="display: none;">采购订单跟踪表</div>
			<div class="grid-subtitle"></div>
			<table id="grid"></table>
			<!--endprint-->
			<div id="page"></div>
		</div>
	</div>
	<!-- <div id="printPage"></div> -->
	<!-- grid end -->

	
</div>


<script language="javascript">

$(function () {
	// $("#btn-printAAA").on("click", function () {
    //     window.focus();
    //     window.print();
    //     return false;
    // });
	var GridHeight;

	var beforePrint = function () {
        console.log("打印前");
		//打印前事件    
		// var jqgridObj=jQuery("#grid");
		// GridHeight = jqgridObj.jqGrid('getGridParam', 'height');//获取高度    
		// jqgridObj.jqGrid('setGridHeight', '100%');//将其高度设置成100%,主要是为了jqgrid 中有Scroll条时  能把该scroll条内内容都打印出来    
		// $("#grid .ui-jqgrid-bdiv").removeClass().addClass("ui-jqgrid-bdiv_self");//去除掉overflow属性


		// var myGrid = $("#grid");
		// var width = myGrid.jqGrid('getGridParam', 'width'); // get current width 
		// width=802;
		// myGrid.jqGrid('setGridWidth', width, true); 
    };

	var afterPrint = function () {
        console.log("打印后");

		// var myGrid = $("#grid");
		// var width = $("#grid-wrap").width(); // get current width 
		// myGrid.jqGrid('setGridWidth', width, true); 
	}


	//监听window状态
    if (window.matchMedia) {
        var mediaQueryList = window.matchMedia('print');
 
        //为印添加事件
        mediaQueryList.addListener(function (mql) {
            if (mql.matches) {
                beforePrint();
            } else {
                afterPrint();
            }
        });
    }
 
    //打印前事件
    window.onbeforeprint = beforePrint;
 
    //打印后事件
    window.onafterprint = afterPrint;
    //执行打印
    $("#btn-printAAA").click(function () {
        $(".cf.box-flex,.mod-search").hide();
		$("#gridTitle").show();
		$(".grid-wrap").css({"padding":0,"border":0});
        var newstr = document.getElementById("grid-wrap").innerHTML;
        window.print();
        $(".cf.box-flex,.mod-search").show();
		$(".grid-wrap").css({"padding":"10px 30px 30px 30px","border":"1px solid #e5e5e5"});
		$("#gridTitle").hide();
    })
})

	
</script>


<script type="text/javascript" src="/public/static/admin/easyui/jeasyui/jquery.easyui.min.js"></script>
<script>
	$(document).ready(function () {
		// 获取当前日期
		var myDate = new Date;
		var year = myDate.getFullYear(); //获取当前年
		var mon = myDate.getMonth() + 1; //获取当前月
		var date = myDate.getDate(); //获取当前日
		// console.log(year + '-' + mon + '-' + date)
		if (mon < 10) {
			mon = "0" + mon;
		}
		if (date < 10) {
			date = "0" + date;
		}
		$("#startdate").val(year + '-' + mon + '-01');
		$("#enddate").val(year + '-' + mon + '-' + date);
	});
</script>

<script type="text/javascript">
	//$action_type 0 查询 1 导出
	function grid_search_list($action_type){
		   $("#ui-print").css({ "visibility": "visible" });  //显示表格数据
			$(".no-query").hide();  //隐藏提示
			// 设置表格高度
			$("#grid").setGridHeight($(window).height() - 230 - $("#filter-menu").height() + "px");

			// 判断是否勾选“小计”
			var groupings=true;
			if ($("#showSubtotalStatus").get(0).checked) {
				groupings=true;
			}else{
				groupings=false;
			}

			var startdate = $('#startdate').val();
			var enddate = $('#enddate').val();
			var supplierid = $('#supplier_id').val();
			var goodsid = $('#goods_id').val();
			var supplier_category_id = $('#supplier_category_id').val();
			//supplier_category_id

			// 高级搜索
			let sn = $('#sn').val();
			let user_category = $('#supplier_category_id').val();
			let jh_time_start = $('#jh_time_start').val();
			let jh_time_end = $('#jh_time_end').val();

			let arr = new Array();
			$('input[name="status"]:checked').each(function () {
				arr.push($(this).val());
			});
			let status = arr.join(',');

			$("div.grid-subtitle").text("日期: " + startdate + " 至 " + enddate);

			$("#ui-print").show();  //显示表格数据
			$(".no-query").hide();  //隐藏提示


			if ($action_type==0) {
				var param={
					'ajax': '100',
					'startdate': startdate,
					'enddate': enddate,
					'supplierid': supplierid,
					'goodsid': goodsid,
					//高级搜索
					sn: sn,
					user_category: user_category,
					jh_time_start: jh_time_start,
					jh_time_end: jh_time_end,
					status: status,
					supplier_category_id: supplier_category_id
				}; //发送数据   
			}else if($action_type==1){
				var param={ 
					'is_export':1,
					'ajax': '100',
					'startdate': startdate,
					'enddate': enddate,
					'supplierid': supplierid,
					'goodsid': goodsid,
					//高级搜索
					sn: sn,
					user_category: user_category,
					jh_time_start: jh_time_start,
					jh_time_end: jh_time_end,
					status: status,
					supplier_category_id: supplier_category_id
				};
				var export_param='';
				for(let key  in param){
					export_param+=key+'='+ param[key]+'&';
				}
				export_param = export_param.substr(0, export_param.length - 1);  
				//console.log(export_param);
				window.location.href="index.html?"+export_param;
				return false;
			}
			//此处可以添加对查询数据的合法验证 
			$("#grid").jqGrid('setGridParam', {
				datatype: 'json',
				postData: param, //发送数据 
				page: 1
			}).trigger("reloadGrid"); //重新载入 
	}
</script>

<script type="text/javascript">
	$(document).ready(function () {
		 // 选择删除
	  //   $("#billDelete").click(function () {
	  //   	var ids = $("#grid").jqGrid('getGridParam','selarrrow');
	  //     	if (ids == '' || ids == null) {
			// 	layer.msg('请先选择需要删除的项！');
			// 	return false;
			// }
			// //获取商品信息
			// $.post('del.html', { id: ids, status: 0,type:2 }, function (res) {
			// 	layer.msg(res.msg);
			// 	if (res.status == 1) {
			// 		reload();
			// 	}
			// });
	  //   })

	    // 导出按钮
		$("#export").click(function () {
			grid_search_list(1);//0 查询 1 导出
		});

		// 点击查询按钮
		$("#search").click(function () {
			grid_search_list(0);//0 查询 1 导出
		});
		
    })
</script>

<script type="text/javascript">

	$(document).ready(function () {

		layui.use('form', function () {
            var form = layui.form;
            //判断按商品排列、按单据排列（单选）
            form.on('checkbox(chk-wrap-filter)', function (data) {
                var v = data.elem.value;
				// console.log(v);
                if (v == 5) {
                    if ($("#chk-wrap-date").get(0).checked) {
						$("#chk-wrap-date").prop("checked", false);
                    	form.render('checkbox');
					}else{
						
					}
                } else if(v == 6) {
                    if ($("#chk-wrap-good").get(0).checked) {
						$("#chk-wrap-good").prop("checked", false);
                    	form.render('checkbox');
					}else{
						
					}
                }
            });
		});


		// // 点击查询按钮
		// $("#filter-submit").click(function () {
			
		// 	//此处可以添加对查询数据的合法验证 
		// 	$("#grid").jqGrid('setGridParam', {
		// 		datatype: 'json',
		// 		grouping:groupings,  //是否显示小计
		// 		postData: {
		// 			'ajax': '100',
		// 			'startdate': startdate,
		// 			'enddate': enddate,
		// 			'supplierid': supplierid,
		// 			'goodsid': goodsid,
		// 			//高级搜索
		// 			sn: sn,
		// 			user_category: user_category,
		// 			jh_time_start: jh_time_start,
		// 			jh_time_end: jh_time_end,
		// 			status: status,
		// 			supplier_category_id: supplier_category_id
		// 		}, //发送数据 
		// 		page: 1
		// 	}).trigger("reloadGrid"); //重新载入 
		// });

		//alert("1111");
		$("#grid").jqGrid({
			url: '/scm/orderinvupreport/index.html?ajax=100',
			datatype: "json",//数据来源，本地数据（local，json,jsonp,xml等）
			height: '90%',//高度，表格高度。可为数值、百分比或'auto'
			width:'100%',
			//width: Public.setGrid().w,
			//height: Public.setGrid().h,
			colNames: ["id", "商品编号", "商品名称", "规格型号", "单位", "订单日期", "采购订单编号", "供应商", "仓库", "状态", "数量", "单价", "采购额", "未入库数量", "未入库金额", "预计交货日期", "最后入库日期", "备注", "商品ID"],
			colModel: [
				{ name: 'id', hidden: true },
				{ name: 'good_sn', index: 'id', width: 80, label: "商品编号" },
				{ name: 'good_name', index: 'name asc', width: 200, label: "商品名称" },
				{ name: 'good_model', index: 'name asc', width: 60, label: "规格型号" },
				{ name: 'unit_name', index: 'name asc', width: 50, label: "单位", align: "center" },
				{ name: 'dj_time', index: 'name asc', width: 80, label: "订单日期", align: "center" },
				{ name: 'sn', index: 'name asc', width: 120, label: "采购订单编号", align: "center" },
				{ name: 'customer_name', index: 'name asc', width: 150, label: "供应商" },
				{ name: 'store_name', index: 'name asc', width: 120, label: "仓库" },
				{ name: 'order_status', index: 'name asc', width: 60, label: "状态", summaryType: 'sum', summaryTpl: '<b> 小计 </b>', formatter: 'count' },
				{ name: 'shuliang', index: 'name asc', width: 50, label: "数量", align: "right", summaryType: 'sum', summaryTpl: '<b> {0}</b>', formatter: 'number' },
				{ name: 'hs_price', index: 'name asc', width: 100, label: "单价", align: "right" },
				{ name: 'total_price', index: 'name asc', width: 100, label: "采购额", align: "right", summaryType: 'sum', summaryTpl: '<b> {0}</b>', formatter: 'number' },
				{ name: 'w_ruku_shuliang', index: 'name asc', width: 80, label: "未入库数量", align: "right", summaryType: 'sum', summaryTpl: '<b> {0}</b>', formatter: 'number' },
				{ name: 'w_ruku_jine', index: 'name asc', width: 80, label: "未入库金额", align: "right", summaryType: 'sum', summaryTpl: '<b> {0}</b>', formatter: 'number' },
				{ name: 'jh_time', index: 'name asc', width: 80, label: "预计交货日期" },
				{ name: 'last_ruku_time', index: 'name asc', width: 80, label: "最后入库日期" },
				{ name: 'mark', index: 'name asc', width: 180,  label: "备注" },
				{ name: 'good_id', hidden: false },
			],
		
			rowNum: 10,
			rowList: [10, 20, 30],
			sortname: 'id',
			sortorder: "desc",
			pagerpos: "left",//分页位置

			pgbuttons: true,//翻页按钮
			pagination: true,
			altRows: !0,
			gridview: !0,
			shrinkToFit: !1,
			autoScroll: false, 
			cellLayout: 8,
			autowidth: !0,
			pager: "#page",
			viewrecords: !0,
			cmTemplate: {
				sortable: !1,
				title: !1
			},
			// 合计
			footerrow: true,
			gridComplete: function () {
				var numbers = parseFloat($("#grid").getCol('number', false, 'sum')).toFixed(2);
				var sum_price_taxs = parseFloat($("#grid").getCol('sum_price_tax', false, 'sum')).toFixed(2);
				var rukuNums = parseFloat($("#grid").getCol('rukuNum', false, 'sum')).toFixed(2);
				var rukuMoneys = parseFloat($("#grid").getCol('rukuMoney', false, 'sum')).toFixed(2);
				$("#grid").footerData('set', { "goods_sn": '合计:', number: numbers, sum_price_tax: sum_price_taxs, rukuNum: rukuNums, rukuMoney: rukuMoneys });

				// 合并合计单元格
				var $footRow = $("#grid").closest(".ui-jqgrid-bdiv").next(".ui-jqgrid-sdiv").find(".footrow");
				$footRow.find('>td[aria-describedby="grid_goods_sn"],>td[aria-describedby="grid_goods_name"],>td[aria-describedby="grid_goods_model"],>td[aria-describedby="grid_unit_name"],>td[aria-describedby="grid_addtime"],>td[aria-describedby="grid_sn"],>td[aria-describedby="grid_customer_name"],>td[aria-describedby="grid_store_name"]').css("border-right-color", "transparent");


			},
			loadError: function (t, e, i) {
				parent.Public.tips({
					type: 1,
					content: "操作失败了哦，请检查您的网络链接！"
				})
			},
			//双击表格行事件
			ondblClickRow: function (row) {
				var rowData = $('#grid').jqGrid('getRowData', row);
				parent.tab.addTabItem({
					tabid: "purchase-purchase2",
					text: "购货订单",
					url: "/scm/invpo/edit.html?id=" + rowData.id,
				})
			},
			//开启分组
			grouping: true,
			groupingView: {
				groupField: ['good_id'], //需要分组的列
				groupSummary: [true],         //是否显示汇总  如果为true需要在colModel中进行配置 如： summaryType:'sum', summaryTpl:'<b>小计: {0}</b>''
				groupColumnShow: [false],      //是否显示分组列
				groupCollapse: false,         //该属性表示在加载数据的时候是否只显示分组信息，false表示既显示分组信息也显示每个分组里面的详细信息，true则只显示分组信息
			},

		});

		var headH = 0;  //顶部搜索是否展开（1：展开，0：未展开）
		$("#conditions-trigger").click(function () {
			if (headH == 0) {
				headH = 1;
				$("#filterItems").css({ "height": "auto" });
				$("#filter-menu .conditions-trigger>b").addClass("act");
				// 设置表格高度
				$("#grid").setGridHeight($(window).height() - 230 - $("#filter-menu").height() + "px");
			} else {
				headH = 0;
				$("#filterItems").css({ "height": "44px" });
				$("#filter-menu .conditions-trigger>b").removeClass("act");
				// 设置表格高度
				$("#grid").setGridHeight($(window).height() - 230 - $("#filter-menu").height() + "px");
			}
		});

	});



</script>

{include file="admin@public/footer"/}